/*
 * Created by JFormDesigner on Wed May 09 09:14:24 EEST 2012
 */

package tr.gov.tubitak.bilgem.esya.crlviewer;

import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;

/**
 * @author Haydar Karabas
 */
public class ECRLDialog extends JDialog {
    public ECRLDialog(Frame owner) {
        super(owner);
        initComponents();
        initGUI();
    }

    public ECRLDialog(Dialog owner) {
        super(owner);
        initComponents();
        initGUI();
    }



    public static void showCRL(byte[] crlData)
    {
        ECRLDialog crlDialog = new ECRLDialog((Dialog) null);
        crlDialog.loadCRL(crlData);
        crlDialog.setVisible(true);
    }

    public static void showCRL(File crlFile)
    {
        ECRLDialog crlDialog = new ECRLDialog((Dialog) null);
        crlDialog.loadCRL(crlFile);
       crlDialog.setVisible(true);
    }


    void loadCRL(byte [] crlData){
        eCRLPanel1.loadCrl(crlData);
    }

    void loadCRL(File crlFile){
        eCRLPanel1.loadCrl(crlFile);
    }


    void initGUI(){
        loadWindowIcon();
    }

    void loadWindowIcon()
    {
        ImageIcon windowIcon = EImageManager.getInstance().getImageIcon("crl.png", "crl.png");
        if(windowIcon != null)
        {
            setIconImage(windowIcon.getImage());
        }
    }

    private void okButtonActionPerformed(ActionEvent e) {
        setVisible(false);
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        ResourceBundle bundle = ResourceBundle.getBundle("tr.gov.tubitak.bilgem.esya.crlviewer.lang");
        dialogPane = new JPanel();
        contentPanel = new JPanel();
        eCRLPanel1 = new ECRLPanel();
        buttonBar = new JPanel();
        okButton = new JButton();

        //======== this ========
        setTitle(bundle.getString("ECRLDialog.sertifikaiptallistesi"));
        setModal(true);
        Container contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());

        //======== dialogPane ========
        {
            dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));
            dialogPane.setLayout(new BorderLayout());

            //======== contentPanel ========
            {
                contentPanel.setLayout(new BorderLayout());
                contentPanel.add(eCRLPanel1, BorderLayout.CENTER);
            }
            dialogPane.add(contentPanel, BorderLayout.CENTER);

            //======== buttonBar ========
            {
                buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
                buttonBar.setLayout(new GridBagLayout());
                ((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 80};
                ((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0};

                //---- okButton ----
                okButton.setText(bundle.getString("ECRLViewer.okButton.text"));
                okButton.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        okButtonActionPerformed(e);
                    }
                });
                buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
                    GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                    new Insets(0, 0, 0, 0), 0, 0));
            }
            dialogPane.add(buttonBar, BorderLayout.SOUTH);
        }
        contentPane.add(dialogPane, BorderLayout.CENTER);
        setSize(425, 535);
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JPanel dialogPane;
    private JPanel contentPanel;
    private ECRLPanel eCRLPanel1;
    private JPanel buttonBar;
    private JButton okButton;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
